package java8.test.closure;

import java.util.function.Consumer;
import java.util.function.Supplier;

//闭包 提升变量的生命周期
public class Learning01 {

    public static Supplier<Integer> test01(){
        int num = 10;
        return () -> {
            return num;
        };
    }

    public static void test02(){
        int s = 10;
        Consumer<Integer> c = e -> {
            System.out.println(s);
        };
        c.accept(1);
    }

    public static void main(String[] args) {
        int n = test01().get();
        System.out.println(n);
        test02();
    }

}
